package com.example.administrator.yunniuusedcar.adapter;

import android.content.Context;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import com.example.administrator.common.ui.BaseAdapterRV;
import com.example.administrator.common.ui.BaseHolderRV;
import com.example.administrator.yunniuusedcar.holder.Home01HeaderHolder;
import com.example.administrator.yunniuusedcar.holder.Home02GridCarHolder;
import com.example.administrator.yunniuusedcar.holder.Home03foolHolder;
import com.example.administrator.yunniuusedcar.model.mode_benn.ADbeen;
import com.example.administrator.yunniuusedcar.model.mode_benn.Home;
import com.example.administrator.yunniuusedcar.model.mode_benn.HomeMenuBean;
import com.example.administrator.yunniuusedcar.model.mode_benn.HomeRanCarListBean;

import java.util.List;

/**
 * Created by USER2015 on 2017/12/15.
 */

public class HomeAdapter extends BaseAdapterRV {        //extends BaseAdapterRV

    public HomeAdapter(Context context, List listData) {
        super(context, listData);
    }

    // viewType: 判断用来显示哪一种类型的item布局
    @Override
    public BaseHolderRV createViewHolder(Context context, ViewGroup parent, int viewType) {
        switch (viewType) {
            case ITEM_TYPE_AD:
          return new Home01HeaderHolder(context, parent, this);      //   广告 列表项

            case ITEM_TYPE_SHOP:
                return new Home02GridCarHolder(context, parent, this);    // 主菜单  Home02GridCarHolder

            case ITEM_TYPE_HEADER:
                return new Home03foolHolder(context, parent, this);      // 随机汽车 列表项
        }

        return null;
    }

    // 列表显示的三种类型
    private static final int ITEM_TYPE_AD = 0;
    private static final int ITEM_TYPE_SHOP = 1;
    private static final int ITEM_TYPE_HEADER = 2;

    // 判断列表项要显示的是哪一种类型
    @Override
    public int getItemViewType(int position) {
        Object bean = getItem(position);

        if (bean instanceof ADbeen) { // 广告 列表项
            return ITEM_TYPE_AD;
        }
        if (bean instanceof HomeMenuBean) {     // 主菜单 列表项
            return ITEM_TYPE_SHOP;
        }

        if (bean instanceof HomeRanCarListBean) {      // 随机汽车 列表项
            return ITEM_TYPE_HEADER;
        }

        return -1;
    }

}
